package com.wisdytech.linkdcs.account.action;


import com.wisdytech.common.handler.ResourceMatchingService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.common.utils.DataTransformUtil;
import com.wisdytech.linkdcs.account.model.Property;
import com.wisdytech.linkdcs.account.service.IPropertyService;
import com.wisdytech.linkdcs.factory.model.Factory;
import com.wisdytech.linkdcs.factory.vo.FactoryVO;
import com.wisdytech.linkdcs.system.model.SysUser;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author chenbin
 * @since 2018-07-19
 */
@Controller
@RequestMapping("/equipment/property")
public class PropertyAction {

	
    /**
     * 注入iPropertyService
     */
    @Autowired
    @Qualifier("iPropertyService")
    private IPropertyService iPropertyService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    /**
    *
    * <p>Description: 设备信息</p>
    * @param model model
    * @return String
    */
   @RequestMapping("/index")
   public String equipmentIndex(Model model, HttpServletRequest httpRequest){
       this.resourceMatchingService.getResourceName(httpRequest,model);
       return "platformAccount/property";
   }
   
   
   /**
    * @param filter 分页参数
    * @throws IOException 
    */
   @RequestMapping(value = "/listPropertyByFilter/get.mvc")
   @ResponseBody
   public StandardTableResult<Property> listPropertyByFilter(Filter filter) throws IOException{
   		PageInfo<Property> propertys =this.iPropertyService.listPropertyByFilter(filter);
       return new StandardTableResult<Property>(propertys.getTotal(),propertys.getList());
   }
   
   /**
    * 保存
    * @param property 属性对象
    * @param session 
    * @return 保存结果集
    */
   @RequestMapping(value = "/saveProperty/save.mvc")
   @ResponseBody
   public StandardResult saveOperation(Property property, HttpSession session) {
       SysUser sysUser = BaseUtil.getCurrentUser();
       String loginName = sysUser.getUsername();
       if (StringUtils.isBlank(property.getPkId())) {
    	   iPropertyService.addProperty(property, loginName);
       }else {
    	   iPropertyService.updateProperty(property, loginName);
       }
       return  StandardResult.getSuccessResult();
   }
   
   
   /**
    * 通过id获取
    * @param id 主键id
    */
   @RequestMapping(value = "/getPropertyById/get.mvc")
   @ResponseBody
   public StandardResult getPropertyById(String pkId) {
	   Property property = iPropertyService.getPropertyById(pkId);
       return StandardResult.getSuccessResult(property);
   }
   
   
   /**
    * 通过id批量删除
    * @param id 主键id
    * @return 删除结果集
    */
   @RequestMapping(value = "/delPropertyById/del.mvc")
   @ResponseBody
   public StandardResult delFactoryById(String pkIds) {
	   iPropertyService.delPropertyById(pkIds);
       return StandardResult.getSuccessResult();
   }
   
   
   /**
    * @param filter 分页参数
    * @throws IOException 
    */
   @RequestMapping(value = "/listPropertyAll/get.mvc")
   @ResponseBody
   public StandardResult listPropertyAll(){
   		List<Property> propertys =this.iPropertyService.listPropertyAll();
       return StandardResult.getSuccessResult(propertys);
   }
}

